package com.mark.toolImpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;

import com.jdbcUtil.JDBCUtil;
import com.mark.database.Mark1;
import com.mark.database.Mark2;

public class GetMarkImpl {
		//获取类型工作1收藏(返回单个)
		public boolean getMark1(Mark1 m1){
			Connection conn=null;
			PreparedStatement ps=null;
			ResultSet rs=null;
			try{
				conn=JDBCUtil.getConnection();
				String sql="select * from mark1 where uid = "+m1.getUid()+" and job1id = "+m1.getJobId()+";";
				ps=conn.prepareStatement(sql);
				rs=ps.executeQuery();
				while(rs.next()){
					return true;
				}
			}catch(Exception e){
				System.out.println(e);
			}finally{
				JDBCUtil.free(conn, ps, rs);
			}
			return false;
			
		}
		//获取类型工作1收藏(返回多个)
		public ArrayList<Mark1> getMark1List(int Uid){
			ArrayList<Mark1> list=new ArrayList<Mark1>();
			Connection conn=null;
			PreparedStatement ps=null;
			ResultSet rs=null;
			try{
				conn=JDBCUtil.getConnection();
				String sql="SELECT  *  FROM mark1 where uid = "+Uid+" ORDER BY markid DESC LIMIT 0, 5;";
				ps=conn.prepareStatement(sql);
				rs=ps.executeQuery();
				while(rs.next()){
					System.out.println("GetMarkImpl.getMark1List()");
					Mark1 m1=new Mark1();
					m1.setMarkId(rs.getInt("markid"));
					m1.setJobId(rs.getInt("job1id"));
					m1.setUid(rs.getInt("uid"));
					list.add(m1);
				}
			}catch(Exception e){
				System.out.println(e);
			}finally{
				JDBCUtil.free(conn, ps, rs);
			}
			return list;
		}
		//获取类型工作2收藏(返回单个)
				public boolean getMark2(Mark2 m2){
					Connection conn=null;
					PreparedStatement ps=null;
					ResultSet rs=null;
					try{
						conn=JDBCUtil.getConnection();
						String sql="select * from mark2 where uid = "+m2.getUid()+" and job2id = "+m2.getJobId()+";";
						ps=conn.prepareStatement(sql);
						rs=ps.executeQuery();
						if(rs.next()){
							return true;
						}
					}catch(Exception e){
						System.out.println(e);
					}finally{
						JDBCUtil.free(conn, ps, rs);
					}
					return false;
					
				}
				//获取类型工作2收藏(返回多个)
		public ArrayList<Mark2> getMark2List(int Uid){
			ArrayList<Mark2> list=new ArrayList<Mark2>();
			Connection conn=null;
			PreparedStatement ps=null;
			ResultSet rs=null;
			try{
				conn=JDBCUtil.getConnection();
				String sql="select * from mark2 where uid = "+Uid+" order by markid LIMIT 0, 4;";
				ps=conn.prepareStatement(sql);
				rs=ps.executeQuery();
				while(rs.next()){
					Mark2 m2=new Mark2();
					m2.setMarkId(rs.getInt("markid"));
					m2.setJobId(rs.getInt("job2id"));
					m2.setUid(rs.getInt("uid"));
					list.add(m2);
				}
			}catch(Exception e){
				System.out.println(e);
			}finally{
				JDBCUtil.free(conn, ps, rs);
			}
			return list;
		}
}
